<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=pageContext.getServletContext().getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/demo/demo.css">
	<script type="text/javascript" src="<%=path %>/eazyui/jquery.min.js"></script>
	<script type="text/javascript" src="<%=path %>/eazyui/jquery.easyui.min.js"></script>
	<style type="text/css">
	#content{
		width:90%;
		padding:10px;
		margin:0 auto;
	}
	</style>
	<script type="text/javascript">
	function getUuid (len, radix) {
                var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
                var uuid = [], i;
                radix = radix || chars.length;
                if (len) {
                  for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
                } else {
                  var r;
                  uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
                  uuid[14] = '4';
                  for (i = 0; i < 36; i++) {
                    if (!uuid[i]) {
                      r = 0 | Math.random()*16;
                      uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
                    }
                  }
                }
                return uuid.join('');
            };
	
	function onLoadSuccess(){
		$("a[name='diagnosisbtn']").linkbutton({
		    iconCls: ''
		});
	}
	function formatterBtn(value,row,index){
		var str = '<a href="#" class="easyui-linkbutton" title="诊断信息增删改" onclick="adDiagnosis(&quot;'+row.guahao_id+'&quot;,'+index+');">诊断信息</a> &nbsp;&nbsp;'
		  +'<a href="<%=path %>/WM?guahao_id='+row.guahao_id+'"  class="easyui-linkbutton" title="转到处方页面"  >转到处方页面</a>';
		return str;	
	}
	function adDiagnosis(guahao_id,index){
		$("#diagnosis").window("open");
		var b=getUuid(32, 16)
		if(guahao_id!=""){
			
			$.get("<%=path %>/uncheck/getRegisterByGuahaoId",{guahao_id:guahao_id},function(data,textStatus){
				
					$("#guahao_idd").textbox("setValue",guahao_id);
					$("#diagnose_id").textbox("setValue",b);
					
			})
		}
	}
	function addDiagnosis(){
		var diagnose_id=$("#diagnose_id").val();
		var guahao_id=$("#guahao_idd").val();
		var patient_telling=$("#patient_telling").val();
		var present_illness=$("#present_illness").val();
		var past_illness=$("#past_illness").val();
		var allergy_illness=$("#allergy_illness").val();
		var date_illness=$("#date_illness").val();
		var diagnose_content=$("#diagnose_content").val();
		var diagnose_remark=$("#diagnose_remark").val();
		var plan_illness=$("#plan_illness").val();
		$.ajax({
			url:"<%=path %>/uncheck/insertDiagnosis",
			data:{diagnose_id:diagnose_id,guahao_id:guahao_id,patient_telling:patient_telling,present_illness:present_illness,past_illness:past_illness,allergy_illness:allergy_illness,date_illness:date_illness,diagnose_content:diagnose_content,diagnose_remark:diagnose_remark,plan_illness:plan_illness},
			/*dataType:"json",*/
			success:function(data,textStatus){
				if(textStatus=="success"){
					
					if(data==true){
						alert("添加成功");
						onLoadSuccess();
						$('#diagnosis').window("close");
					}
				}
			},
			error:function(data,textStatus){
				alert(textStatus+":发病日期的格式应为 xxxx-xx-xx");
			},
		})
		
	}
	</script>
</head>
<body>
<div id="pageone" title="Waiting for diagnosis">
	<table id="dg" class="easyui-datagrid" style="width: 100%" data-options="onLoadSuccess:onLoadSuccess">
    <thead>
		<tr>
			<th field="card_id" width=30%>卡号</th>
			<th field="guahao_id" width=30%>挂号id</th>
			<th field="patient_name" width="10%">姓名</th>
			<th data-options="field:'action',formatter:formatterBtn" width="30%">操作</th>
		</tr>
    </thead>
    <tbody>
    <c:forEach items="${register }" var="registered">
    	<tr>
			<td>${registered.patient.card_id }</td>
			<td>${registered.guahao_id }</td>
			<td>${registered.patient.patient_name }</td>
		</tr>
	</c:forEach>
		
	</tbody>
	</table>
	<div id="diagnosis" class="easyui-window" title="诊断信息" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px;height:550px;padding:10px;">
		<div style="margin:0 auto;width:70%;">
			<div style="margin:5px auto;">
				<input id="diagnose_id" style="width:100%;height:25px" class="easyui-textbox" readonly="readonly">
				<div>挂号id:</div>
				<input class="easyui-textbox" id="guahao_idd" style="width:100%;height:25px" readonly="readonly">
				<div>主诉:</div>
				<input class="easyui-textbox" id="patient_telling" style="width:100%;height:25px">
				<div>现病史:</div>
				<input class="easyui-textbox" id="present_illness" style="width:100%;height:25px">
				<div>以往病史:</div>
				<input class="easyui-textbox" id="past_illness" style="width:100%;height:25px">
				<div>过敏史:</div>
				<input class="easyui-textbox" id="allergy_illness" style="width:100%;height:25px">
				<div>发病日期:</div>
				<input class="easyui-textbox" id="date_illness" style="width:100%;height:25px">
				<div>诊断内容:</div>
				<input class="easyui-textbox" id="diagnose_content" style="width:100%;height:60px">
				<div>诊断备注:</div>
				<input class="easyui-textbox" id="diagnose_remark" style="width:100%;height:60px">
				<div>处置计划:</div>
				<input class="easyui-textbox" id="plan_illness" style="width:100%;height:60px">			
			</div>
			<div style="margin-top:30px">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" style="width:100%;height:32px" onclick="addDiagnosis();">保存</a>
			</div>
		
		</div>
	</div>
</div>
</body>
</html>